//
//  WSListPlaceHolderView.m
//  jdd
//
//  Created by 王诗文 on 2018/8/8.
//

#import "WSListPlaceHolderView.h"
#import "UIView+CKFrame.h"
#import "NSBundle+WSBundle.h"

@interface WSListPlaceHolderView()


@end;

@implementation WSListPlaceHolderView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame{
     if (self = [super initWithFrame:frame]) {
          [self initSubViews];
     }
     return self;
}

- (void)initSubViews
{

     
     _holderImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 173, 181)];
     [self addSubview:_holderImageView];
     
     _descLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 20)];
     _descLabel.textAlignment = NSTextAlignmentCenter;
     _descLabel.textColor = [UIColor colorWithRed:153.0/255.0 green:153.0/255.0 blue:153.0/255.0 alpha:1.0];
     _descLabel.font = [UIFont systemFontOfSize:14];
     [self addSubview:_descLabel];
     
     _retryButton = [[UIButton alloc] init];
     [_retryButton setTitleColor:[UIColor colorWithRed:84.0/255.0 green:120.0/255.0 blue:202.0/255.0 alpha:1.0] forState:UIControlStateNormal];
     [_retryButton addTarget:self action:@selector(retryButtonClick:) forControlEvents:UIControlEventTouchUpInside];
     _retryButton.titleLabel.font = [UIFont systemFontOfSize:14];
     [self addSubview:_retryButton];
     
     _loginButton = [[UIButton alloc] init];
     [_loginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
     [_loginButton setTitle:@"登录" forState:UIControlStateNormal];
     [_loginButton addTarget:self action:@selector(loginButtonClick:) forControlEvents:UIControlEventTouchUpInside];
     _loginButton.titleLabel.font = [UIFont systemFontOfSize:14];
     _loginButton.backgroundColor = [UIColor colorWithRed:248.0/255.0 green:73.0/255.0 blue:72.0/255.0 alpha:1.0];
     _loginButton.layer.cornerRadius = 5;
     [self addSubview:_loginButton];
     
}


- (void)retryButtonClick:(UIButton *)btn{
     if (self.delegate&& [self.delegate respondsToSelector:@selector(holderButtonClickWithStatus:)]) {
          [self.delegate holderButtonClickWithStatus:self.listStatus];
     }
}

- (void)loginButtonClick:(UIButton *)btn{
     if (self.delegate&& [self.delegate respondsToSelector:@selector(holderButtonClickWithStatus:)]) {
          [self.delegate holderButtonClickWithStatus:self.listStatus];
     }
}

#pragma mark - set\get
- (void)setListStatus:(WSListStatus)listStatus{
     _listStatus = listStatus;
    
    _holderImageView.ck_centerX = self.center.x;
    _holderImageView.ck_centerY = self.center.y - 50;
     [self.loginButton setHidden:YES];
     if (listStatus==WSListStatusNone) {
         
          self.holderImageView.image = [NSBundle ws_nodataImage];
//          [self.retryButton setTitle:@"点击刷新" forState:UIControlStateNormal];
          self.descLabel.text = @"暂无数据";
        
         _holderImageView.ck_width = 140;
         _holderImageView.ck_height = 100;
         _descLabel.ck_centerX = self.center.x;
         _descLabel.ck_top = self.holderImageView.ck_bottom + 20;
//          [_retryButton mas_remakeConstraints:^(MASConstraintMaker *make) {
//               @strongify(self);
//               make.centerY.equalTo(self.descLabel.mas_centerY);
//               make.left.equalTo(self.descLabel.mas_right);
//               make.size.mas_equalTo(CGSizeMake(60, 16));
//          }];
          
     }else if(listStatus==WSListStatusFails){
          [self.retryButton setTitle:@"点击刷新" forState:UIControlStateNormal];
          self.descLabel.text = @"啊哦~接口无响应";
          self.holderImageView.image = [NSBundle ws_failedImage];
         
         _holderImageView.ck_width = 173;
         _holderImageView.ck_height = 181;
       
         _descLabel.ck_centerX = self.center.x - 30;
         _descLabel.ck_top = self.holderImageView.ck_bottom + 20;
      
         _retryButton.ck_centerY = self.descLabel.ck_centerY;
         _retryButton.ck_left = self.descLabel.ck_right;
         _retryButton.ck_size = CGSizeMake(60, 16);
     }
     else if(listStatus==WSListStatusLogin){
          
          [self.retryButton setTitle:@"" forState:UIControlStateNormal];
          self.descLabel.text = @"您还没有登录，点击进行登录";
          self.holderImageView.image = [NSBundle ws_failedImage];
          [self.loginButton setHidden:NO];
         
         _holderImageView.ck_width = 173;
         _holderImageView.ck_height = 181;
   
         _descLabel.ck_centerX = self.center.x;
         _descLabel.ck_top = self.holderImageView.ck_bottom + 20;
     
         _loginButton.ck_centerX = self.ck_centerX;
         _loginButton.ck_top = self.descLabel.ck_bottom + 25;
         _loginButton.ck_size = CGSizeMake(80, 35);
     }
}

@end
